package com.suep.business.mapper;

import com.suep.business.domain.UserAddress;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface UserAddressMapper {

    // 主键精确查询
    @Select("SELECT * FROM user_address WHERE address_id = #{addressId}")
    UserAddress selectUserAddressById(@Param("addressId") Integer addressId);

    // 外键查询
    @Select("SELECT * FROM user_address WHERE user_id = #{userId}")
    List<UserAddress> selectUserAddressByUserId(@Param("userId") Integer userId);

    // 主键精确删除
    @Delete("DELETE FROM user_address WHERE address_id = #{addressId}")
    Integer deleteUserAddressById(@Param("addressId") Integer addressId);

    // 插入
    @Insert("INSERT INTO user_address (user_id, address_detail, longitude, latitude, is_default) " +
            "VALUES (#{userId}, #{addressDetail}, #{longitude}, #{latitude}, #{isDefault})")
    Integer insertUserAddress(UserAddress userAddress);

    // 更新
    @Update("UPDATE user_address SET user_id = #{userId}, address_detail = #{addressDetail}, " +
            "longitude = #{longitude}, latitude = #{latitude}, is_default = #{isDefault} " +
            "WHERE address_id = #{addressId}")
    Integer updateUserAddressById(UserAddress userAddress);
}
